{extend name="public/container"}
{block name='head_top'}
<script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/ueditor/third-party/zeroclipboard/ZeroClipboard.js"></script>
<script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="{__ADMIN_PATH}plug/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="{__ADMIN_PATH}plug/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="{__PC_KS3}src/async.min.js"></script>
{/block}
{block name="content"}
<style type="text/css">
    /** 分销弹窗样式重置开始 */
    .avatar-uploader .el-upload {
        width: 200px;
        height: 300px;
    }
    .el-dialog__body {padding: 10px 20px;}
    .el-form-item {margin-bottom: 18px;}
    /** 分销弹窗样式重置开始 */
</style>
<div id="myApp" v-cloak>
    <div class="padding-10">
        <div class="douxue-filter flex flex-between" style="margin-bottom:20px;">
            <el-form :inline="true" :model="where" size="mini" class="flex">
                <div class="flex flex-between">
                    <el-form-item>
                        <el-select v-model="where.status" clearable placeholder="线路状态">
                            <el-option label="正常" value="1"></el-option>
                            <el-option label="禁用" value="0"></el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item>
                        <el-select v-model="where.route_type" clearable placeholder="线路类型">
                            <el-option label="长线" value="1"></el-option>
                            <el-option label="短线" value="2"></el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item>
                        <el-input size="small" v-model="where.route_name" placeholder="线路名称">
                            <el-button slot="append" size="small" type="primary" @click="doLoadRows(1)" icon="el-icon-search"></el-button>
                        </el-input>
                    </el-form-item>
                </div>
            </el-form>

            <el-button type="primary" size="mini" @click="doAdd()">新增线路</el-button>
        </div>
        <div class="">
            <el-table
                :data="rows"
                style="width: 100%"
                v-loading="loading"
                element-loading-text="加载中"
                element-loading-spinner="el-icon-loading"
                size="mini">
                <el-table-column
                    prop="id"
                    label="ID"
                    width="60"
                    align="left">
                </el-table-column>
                <el-table-column
                    prop="route_name"
                    label="线路名称"
                    align="left">
                </el-table-column>
                <el-table-column
                    prop="route_type_text"
                    width="140"
                    label="线路类型"
                    align="left">
                </el-table-column>
                <el-table-column
                    prop="is_return_gold"
                    label="返金币"
                    width="100"
                    align="left">
                    <template slot-scope="scope">
                        <el-tag type="success" size="mini" v-if="scope.row.is_return_gold==1">支持</el-tag>
                        <el-tag type="info" size="mini" v-else>不支持</el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="is_gift_insurance"
                    label="出行险"
                    width="100"
                    align="left">
                    <template slot-scope="scope">
                        <el-tag type="success" size="mini" v-if="scope.row.is_gift_insurance==1">支持</el-tag>
                        <el-tag type="info" size="mini" v-else>不支持</el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                    prop="is_refund_whatever"
                    label="随心退"
                    width="100"
                    align="left">
                    <template slot-scope="scope">
                        <el-tag type="success" size="mini" v-if="scope.row.is_refund_whatever==1">支持</el-tag>
                        <el-tag type="info" size="mini" v-else>不支持</el-tag>
                    </template>
                </el-table-column>
                <el-table-column
                    label="线路状态"
                    width="160"
                    align="left">
                    <template slot-scope="scope">
                        <el-switch
                            v-model="scope.row.status"
                            active-color="#ff6a6c"
                            inactive-color="#999"
                            :active-value="1"
                            :inactive-value="0"
                            @change="doSetStatus(scope.row)">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column
                    label="操作"
                    fixed="right"
                    width="140"
                    align="left">
                    <template slot-scope="scope">
                        <el-link type="primary" size="mini" :underline="false" @click="doAdd(scope.row.id)">编辑</el-link>
                        <el-link type="danger" size="mini" :underline="false" @click="doDelete(scope.row.id)">删除</el-link>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    small
                    :hide-on-single-page="true"
                    layout="prev, pager, next"
                    :total="rowsCount"
                    :page-size="where.limit"
                    @current-change="doLoadRows">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    var my = new Vue({
        el: "#myApp",
        data(){
            return {
                where:{
                    route_name:'',
                    route_type: '',
                    status: '',
                    page:1,
                    limit:pageSize
                },
                loading:false,
                rowsCount: 0,
                rows: [],
            }
        },
        methods: {
            doLoadRows (page) {
                this.loading = true
                this.where.page  = page || 1
                axios.get(Url({a:'get_list' , q:this.where}))
                    .then(res => {
                        this.rows = res.data.data
                        this.rowsCount =res.data.count
                        this.loading = false
                    })
            }
            ,doSetStatus (row) {
                axios.get(Url({a:'set_status',q:{status:row.status,id:row.id}}))
                    .then(res => {
                        this.$message({
                            message: res.data.msg,
                            type: res.data.code === 200 ? 'success' : 'error',
                            onClose: _ => {
                                if (res.data.code !== 200) {
                                    this.doLoadRows()
                                }
                            }
                        })
                    })
            }
            ,doAdd (id) {
                if ( id != null ) return window.location.href = Url({a:'add',q:{id:id}})

                return window.location.href = Url({a:'add'})
            },
            doDelete (id) {
                this.$confirm('确认删除该条记录?').then(_ => {
                    axios.get(Url({a:'delete' , q:{id:id}})).then(res => {
                        this.$message({
                            message: res.data.msg,
                            type: res.data.code === 200 ? 'success' : 'error',
                        })
                    }).catch(_ => {
                        this.$message({
                            message: '删除失败',
                            type: 'error'
                        })
                    })

                    return this.doLoadRows();
                }).catch(_ => {})
            }
        },
        mounted(){
            this.doLoadRows()
        }
    })
</script>
{/block}